package cn.tfyhyc.springcloud.controller;

import cn.tfyhyc.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author 头发又黑又长
 * @Date 2022/10/22 15:56
 * @email zwb15083976291@163.com
 */
@RestController
@Slf4j
public class NacosOrderController {

    // 配置文件中的生产者服务地址
    @Value("${service-url.nacos-user-service}")
    private String ServerURL;

    @Resource
    private RestTemplate restTemplate;

    @Resource
    PaymentService paymentService;

    @GetMapping("/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id") Long id) {
        return restTemplate.getForObject(
                String.format(ServerURL + "/payment/nacos/%d", id),
                String.class
        );
    }

    // 使用 openFeign
    @GetMapping("/consumer/payment/feign/nacos/{id}")
    public String paymentInfo2(@PathVariable("id") Long id) {
        return paymentService.nacosPaymentById(id);
    }
}
